/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing.Design;
using EnvDTE80;
using System.Windows.Forms;

namespace DaveSexton.DocProject.Sandcastle.BuildComponents.Editors
{
	public sealed class SandcastleBuildComponentBasicEditor : UITypeEditor
	{
		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="SandcastleBuildComponentBasicEditor" /> class.
		/// </summary>
		public SandcastleBuildComponentBasicEditor()
		{
		}
		#endregion

		#region Methods
		public static DialogResult ShowDialog(IWin32Window owner, SandcastleBuildComponent component)
		{
			using (SandcastleBuildComponentBasicEditorDialog dialog = new SandcastleBuildComponentBasicEditorDialog(component))
			{
				DialogResult result = dialog.ShowDialog(owner);

				if (result == DialogResult.OK)
				{
					component.CommentDescription = dialog.Description;
					component.ConfigurationAsString = dialog.Configuration;
				}

				return result;
			}
		}

		[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
		public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

		[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			return ShowDialog(DocProjectEnvironment.MainWindow, (SandcastleBuildComponent) value) == DialogResult.OK;
		}
		#endregion
	}
}
